<template>
	<view class="container">
		<view>
			<!-- 顶部搜索 -->
			<view class="searchMd">
				<image src="https://pubuimg.cqguanjie.cn/chat/16939071551012" class="searImgs"></image>
				<view class="searchBox" @click="$goURl('/pages/news/newsSearch')">
					<view>
						<uni-icons type="search" size="16" color="#cfcfcf" ></uni-icons>
						<span class="searchText">搜索新闻资讯</span>
					</view>
					<view class="searchBottm">
						<span class="searchBottmText">搜索</span>
					</view>
				</view>
			</view>
			<!-- 新闻导航 -->
			<view class="newsConten">
				<scroll-view :scroll-x="true" class="scroll-view_H" show-scrollbar="false">
					<view class="newsNext">
						<view class="newsFor" v-for="(item,index) in data.newsList" :key="index" @click="navigationClick(item.ID)" :class="item.ID==data.navigColor?'actve':''">
							<text class="newsNaver">{{item.name}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 轮播图 -->

			<view class="content" v-if="data.bannerImg.length">
				<uni-swiper-dot class="uni-swiper-dot-box"  :info="data.bannerImg" :current="data.currentst"
					mode="round"  :dotsStyles="{'selectedBackgroundColor':'#fff','selectedBorder':'#fff','border':'#fff'}" field="right"
					>
					<swiper class="swiper-box" @change="changes">
						<swiper-item v-for="(item, index) in data.bannerImg" :key="index">
							<view class="swiper-item" :class="'swiper-item' + index" @click="$goURl('/pages/news/newsDetails?id='+item.ID)">
								<view style="width: 100%;height: 100%;" v-if="item.code==0">
									<image :src="item.img" ></image>
									<view class="popular">
										<text class="prpuMpp">热点</text>
										<text class="popularText">{{item.title}}</text>
									</view>
								</view>
								<video v-else :src="item.video" ></video>
							</view>
						</swiper-item>
					</swiper>
				</uni-swiper-dot>
			</view>
			<empty v-if="data.newsIndex.length==0"></empty>
			<!-- 新闻列表 -->
			<view class="newsListe">
				<view class="newsFor" v-for="(news,indexs) in data.newsIndex" :key="indexs" @click="$goURl('/pages/news/newsDetails?id='+news.ID)">
					<!-- 新闻左侧 -->
					<view class="newsLeft">
						<text class="newsText">{{news.title}}</text>
						<view class="newsMtd">
							<text class="browse">{{news.click}}次浏览</text>
							<text class="browse">{{$clearTime(news.CreatedAt)}}</text>
						</view>
					</view>
					<!-- 新闻右侧 -->
					<view class="newsRight">
						<image class="newsImg" :src="news.img"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		getCurrentInstance
	} from "vue";
	import {
		onLoad,
		onShow,
		onPullDownRefresh,
		onReachBottom
	} from "@dcloudio/uni-app";
const {proxy} = getCurrentInstance();
	let userInfo = ref({})
	let data = reactive({
		page:0,
		size:50,
		pages:1,
		newsList: [],		//新闻导航栏
		bannerImg:[],		//轮播图
		navigColor:1,		//点击获取id
		currentst:0,
		newsIndex:[],		//新闻列表
	})
	onPullDownRefresh(()=> {
		newsNavigation()
		// rotationChart()
		newsLists()
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		})
	onReachBottom(()=>{
		console.log('onReachBottom')
	})
	onLoad((option) => {
		console.log('页面onLoad')
	})
	onShow(() => {
		console.log('页面onShow')
		newsNavigation()
		// rotationChart()

	})
	function scrolltolower(){
		
	}
	//新闻导航栏
	function newsNavigation(){
		proxy.$request({
			url:`api/navigationList/?page=${data.page}&size=${data.size}`,
			method:'GET',
			success:(res)=>{
				data.newsList = res.data.data
				data.navigColor=res.data.data[0].ID
				newsLists(res.data.data[0].ID)
			}
		})
	}
	// 点击导航栏
	function navigationClick(id){
		console.log(id);
		data.navigColor = id
		newsLists(id)
	}
	//轮播图
	// function rotationChart(){
	// 	proxy.$request({
	// 		url:`carouselList/?page=${data.page}&size=${data.size}&code=1`,
	// 		method:'GET',
	// 		success:(res)=>{
	// 			data.bannerImg = res.data.data
	// 		}
	// 	})
	// }
	//轮播切换
	function changes(e) {
		data.currentst = e.detail.current;
	}
	//新闻列表
	function newsLists(id){
		let newsID = null
		if(id){
			newsID = id
		}else{
			newsID = data.navigColor
		}
		data.bannerImg = []
		proxy.$request({
			url:`api/newsList/${newsID}/?page=${data.page}&size=${data.size}`,
			method:'GET',
			success:(res)=>{
				data.newsIndex = res.data.data
				let min = res.data.data
				min.forEach((ct)=>{
					if(ct.is_hot==1){
						data.bannerImg.push(ct)
					}
				})
			}
		})
	}
</script>
<style lang="scss" scoped>
	page{
		background: #fff;
	}
	// 顶部搜索框
	.searchMd {
		width: 96%;
		display: flex;
		align-items: center;
		margin: 40rpx auto 0 auto;
		.searImgs{
			width: 50rpx !important;
			height: 50rpx !important;
		}
		.searchBox {
			width: 90%;
			border: 1rpx solid rgba(238, 3, 3, 0.15);
			background: #ffffff;
			border-radius: 34rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 4rpx 4rpx 4rpx 20rpx;
			margin-left: 8rpx;
		}

		.searchText {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #cfcfcf;
			letter-spacing: 0rpx;
		}

		.searchBottm {
			background: #ee0303;
			border-radius: 34rpx;
			padding: 6rpx 34rpx 4rpx 34rpx;
		}

		.searchBottmText {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			text-align: left;
			color: #ffffff;
			letter-spacing: 2rpx;
			line-height: 48rpx;
		}
	}
	// 新闻导航
	.newsConten {
		width: 96%;
		margin: 20rpx auto;

		.scroll-view_H {
			white-space: nowrap;
			width: 100%;
		}

		.newsNext {
			display: flex;
			justify-content: flex-start;
		}

		.newsFor {
			// width: 100%;
			font-size: 30rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #333333;
			letter-spacing: 0rpx;
			padding: 0 10rpx;
		}
		.newsNaver{
			width: 80px;
			display: block;
		}
		.actve{
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #000000;
			letter-spacing: 0.02rpx;
		}
	}
	// 轮播图
	.content{
		width: 96%;
		margin: 0 auto;
		position: relative;
		.swiper-item{
			border-radius: 20px;
		}
		.popular{
			width: 94%;
			position: absolute;
			left: 0;
			bottom: 10%;
			padding: 0px 30rpx;
			display: flex;
			flex-direction: column;
		}
		.prpuMpp{
			width: 8%;
			background: #ee0303;
			border-radius: 8rpx;
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #ffffff;
			letter-spacing: 1rpx;
			padding: 4rpx 10rpx;
		}
		.popularText{
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #ffffff;
			letter-spacing: 1rpx;
			overflow:hidden;
			text-overflow:ellipsis;
			display:-webkit-box;
			-webkit-box-orient:vertical;
			-webkit-line-clamp:1; // 想要超出三行显示 就把这里改成3就好了
		}
	}
	// 新闻列表
	.newsListe{
		width: 96%;
		margin: 0 auto;
		.newsFor{
			display: flex;
			border-bottom: 1px solid #eee;
			margin-top: 20rpx;
			padding: 20rpx 0;
		}
		.newsLeft{
			width: 70%;
			padding: 0 20rpx 0 0;
		}
		.newsText{
			font-size: 30rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #333333;
			letter-spacing: 1rpx;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;
		}
		.newsMtd{
			width: 100%;
			margin-top: 30px;
			display: flex;
			justify-content: space-between;
		}
		.browse{
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #999999;
			letter-spacing: 1rpx;
			margin-right: 20rpx;
		}
		.newsRight{
			width: 30%;
		}
		.newsImg{
			height: 200rpx !important;
		}
	}
	uni-image{
		width: 100% !important;
		height: 100% !important;
		object-fit: cover;
		border-radius: 28rpx;
	}
	.swiper-item{
		height: 100% !important;
	}
	uni-swiper{
		height: 400rpx !important;
	}
	::v-deep .uni-swiper__dots-box{
		justify-content: flex-end !important;
		padding: 0 20rpx 0 0;
	}
	uni-video{
		width: 100% !important;
		height: 100% !important;
	}
</style>
<style>
	page{
		background-color: #fff;
	}
</style>